package com.smc.controller;

import com.alibaba.excel.metadata.Sheet;
import com.smc.proxy.TableHeaderExcelProperty;
import com.smc.utils.ExcelUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author C12645
 * @description 导出
 * @date 2021/10/25 16:04
 **/
public class ExportController {
    public static void main(String[] args) {
        String filepath = "G://测试.xlsx";
        /*ArrayList<List<Object>> data = new ArrayList<>();
        data.add(Arrays.asList("111",222,333));
        data.add(Arrays.asList("111",222,333));
        data.add(Arrays.asList("111",222,333));
        List<String> head = Arrays.asList("表头一", "表头二", "表头三");
        ExcelUtil.writeBySimple(filepath,data,head);*/

        ArrayList<TableHeaderExcelProperty> data = new ArrayList<>();
        for(int i = 0; i < 4; i++){
            TableHeaderExcelProperty tableHeaderExcelProperty = new TableHeaderExcelProperty();
            tableHeaderExcelProperty.setName("cmj" + i);
            tableHeaderExcelProperty.setAge(22 + i);
            tableHeaderExcelProperty.setSchool("清华大学" + i);
            data.add(tableHeaderExcelProperty);
        }

        ExcelUtil.writeWithTemplate(filepath,data);
        exportSheet();
    }
    /**
     * 多个sheet 导出
     */
    private static void  exportSheet(){
        ArrayList<ExcelUtil.MultipleSheelPropety> list1 = new ArrayList<>();
        for(int j = 1; j < 4; j++){
            ArrayList<TableHeaderExcelProperty> list = new ArrayList<>();
            for(int i = 0; i < 4; i++){
                TableHeaderExcelProperty tableHeaderExcelProperty = new TableHeaderExcelProperty();
                tableHeaderExcelProperty.setName("cmj" + i);
                tableHeaderExcelProperty.setAge(22 + i);
                tableHeaderExcelProperty.setSchool("清华大学" + i);
                list.add(tableHeaderExcelProperty);
            }

            Sheet sheet = new Sheet(j, 0);
            sheet.setSheetName("sheet" + j);

            ExcelUtil.MultipleSheelPropety multipleSheelPropety = new ExcelUtil.MultipleSheelPropety();
            // 设置内容
            multipleSheelPropety.setData(list);
            // 设置头
            multipleSheelPropety.setSheet(sheet);

            list1.add(multipleSheelPropety);

        }

        ExcelUtil.writeWithMultipleSheel("G://aaa.xlsx",list1);
    }
}
